import Vue from 'vue';
import { Alert,Toast,Loading,Message,MessageBox,Notification  } from 'element-ui';

let loadingInstance= null;

export default {

    /**
     * 成功提示
     * @param msg
     * @param callback
     */
    success:function (msg,callback) {
      Message({
            message: msg,
            type: 'success'
        });
        setTimeout(function () {
            callback&&callback.call(this)
        },2000)

    },
    /**
     * 错误提示
     * @param msg
     * @param callback
     */
    error:function (msg,callback) {
      Message({
          message: msg,
          type: 'error'
        });
        setTimeout(function () {
            callback&&callback.call(this)
        },2000)
    },
    showLoading:function (text="加载中...") {
      loadingInstance= Loading.service({
        lock: true,
        text: text,
        // spinner: 'el-icon-loading',
        background: 'rgba(255,255,255,0.9)'
      });
    },
    hideLoading:function () {
      loadingInstance&&loadingInstance.close();
    },
	
    // /**
    //  * 普通提示，自动消失
    //  * @param msg
    //  * @param callback
    //  */
    tip:function (msg,callback) {
        Toast({
            message: msg
        });
        setTimeout(function () {
            callback&&callback.call(this)
        },2000)
    },
    // /**
    //  * 普通提示，不消失
    //  * @param msg
    //  * @param callback
    //  */
    alert:function (msg,callback,title) {
        MessageBox.alert(msg,title).then(action => {
            callback&&callback.call(this)
        })
    },
    confirm:function (msg,callback) {
        MessageBox.confirm(msg).then(action => {
              callback&&callback.call(this)
          }).catch(() => {
      });
    },
    prompt:function (msg,callback) {
        MessageBox.prompt(msg).then(({ value, action }) => {
            callback&&callback.call(this,value)
        })
    }

}


